#!/bin/bash

#This script builds and runs the game of life on the two directories provided,
#does a check on the different outputs, and does a timing run.

# Some helper functions
function clean_and_build_src {
    local srcDirectory="$1"

    local cleanCommand="make -C $srcDirectory clean"
    local buildCommand="make -C $srcDirectory all"

    echo "Cleaning directory '$srcDirectory'"
    $cleanCommand

    echo "Building directory '$srcDirectory'"
    $buildCommand
}

function usage_and_exit {
cat<<EOF
Checker script for the gol implementation.
This script will check the implementation of the original against the optimized
for correctness and speed.

Usage:
    $0 <original-src-sir> <optimized-src-dir>
EOF
exit $1
}

[ -z "$1" ] && usage_and_exit 1
[ -z "$2" ] && usage_and_exit 1

GOL_ORI_DIR="$(readlink -f $1)"
GOL_OPT_DIR="$(readlink -f $2)"

echo "The original directory supplied is '$GOL_ORI_DIR'"
echo "The original directory supplied is '$GOL_OPT_DIR'"

clean_and_build_src "$GOL_ORI_DIR"
clean_and_build_src "$GOL_OPT_DIR"
